package Code;

import java.util.*;

public class Code49 {
    static List<List<String>>  groupStr(String[] strs){
        List<List<String>> res = new ArrayList<>();

        Map<String, List<String>> map = new HashMap<>();
        for(String str : strs){
            char[] c = str.toCharArray();
            Arrays.sort(c);
            String strKey= new String(c);
            if(!map.containsKey(strKey)){
                map.put(strKey, new ArrayList<>());
            }
            map.get(strKey).add(str);
        }
        return new ArrayList<>(map.values());
    }
    public static void main(String[] args) {
        String[] strs = {"eat", "tea", "tan", "ate", "nat", "bat"};
        List<List<String>> result = groupStr(strs);
        for (List<String> group : result) {
            System.out.println(group);
        }
    }
}
